package Com.Isman.Adapter;

import org.kobjects.base64.Base64;

import Com.Isman.WebService.ComplexType.Image;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class HotelImageAdapter extends BaseAdapter {
        private Bitmap decodedByte;
        private byte[] decodedString;
        private Image[] ImageContent;
        private Context mContext;
        private int mGalleryItemBackground;
      
        public HotelImageAdapter(Context c, Image[] ImageContent) {
        	this.ImageContent = ImageContent;
            this.mContext = c;
        }

        @Override
		public int getCount() {
            return ImageContent.length;
        }

        @Override
		public Object getItem(int position) {
            return ImageContent[position];
        }

        @Override
		public long getItemId(int position) {
            return position;
        }

        @Override
		public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);
            
            decodedString = Base64.decode(ImageContent[position].getContent());
            decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);


            i.setImageBitmap(decodedByte);
            i.setScaleType(ImageView.ScaleType.CENTER_CROP);
            i.setLayoutParams(new Gallery.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,android.view.ViewGroup.LayoutParams.MATCH_PARENT));
            
            // The preferred Gallery item background
            i.setBackgroundResource(mGalleryItemBackground);
            return i;
        }
    }